import streamlit as st
from typing import Optional
from datetime import datetime

class MessageComponent:
    """消息组件"""
    @staticmethod
    def render_message(
        content: str,
        is_user: bool = False,
        timestamp: Optional[str] = None
    ):
        """渲染消息"""
        message_class = "user-message" if is_user else "bot-message"
        
        with st.container():
            # 消息内容
            st.markdown(
                f'<div class="message {message_class}">{content}</div>',
                unsafe_allow_html=True
            )
            
            # 时间戳
            if timestamp:
                st.markdown(
                    f'<div class="message-time">{timestamp}</div>',
                    unsafe_allow_html=True
                )
    
    @staticmethod
    def render_system_message(content: str):
        """渲染系统消息"""
        st.markdown(
            f'<div class="message system-message">{content}</div>',
            unsafe_allow_html=True
        )
    
    @staticmethod
    def render_error_message(content: str):
        """渲染错误消息"""
        st.markdown(
            f'<div class="message error-message">{content}</div>',
            unsafe_allow_html=True
        ) 